#define _CRT_SECURE_NO_WARNINGS 1

#include <stdio.h>
#include <string.h>
#include <stdlib.h>


struct Stu
{
	char name[20];
	int age;
};

void cmp_int(const void *p1,const void *p2)
{
	return *(int*)p1 - *(int*)p2;
}

void arr_print(int* p, int sz)
{
	int i = 0;
	for (i = 0; i < sz; i++)
	{
		printf("%d ", *(p + i));
	}
}

void test_int()
{
	int arr[10] = { 0,2,5,3,4,7,6,9,8,1 };
	int sz = sizeof(arr) / sizeof(arr[0]);
	qsort(arr, sz, sizeof(arr[0]), cmp_int);
	arr_print(arr, sz);
}

void stu_cmp_char(const void* p1, const void* p2)
{
	return strcmp(((struct Stu*)p1)->name, ((struct Stu*)p2)->name);
}

void stu_cmp_int(const void* p1, const void* p2)
{
	return (((struct Stu*)p1)->age) - (((struct Stu*)p2)->age);
}

void test_stu_char()
{
	struct Stu arr[3] = { {"zhangsan", 20},{"lisi",25},{"wangwu",18}};
	int sz = sizeof(arr) / sizeof(arr[0]);
	qsort(arr, sz, sizeof(arr[0]), stu_cmp_char);
}

void test_stu_int()
{
	struct Stu arr[3] = { {"zhangsan", 20},{"lisi",25},{"wangwu",18} };
	int sz = sizeof(arr) / sizeof(arr[0]);
	qsort(arr, sz, sizeof(arr[0]), stu_cmp_int);

}



int main()
{
	//test_int();
	//test_stu_char();
	test_stu_int();
}
